﻿using Best.SmartCms.Dto.Login;
using Best.SmartCms.Dto.Response;
using Best.SmartCms.Service.Common;
using Best.SmartCms.Service.Security;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;

namespace Best.SmartCms.API.Controllers
{
    /// <summary>
    /// 登入验证
    /// </summary>
    public class LoginController : Controller
    {
        private readonly LoginService _loginService;
        private readonly IWebHostEnvironment _hostingEnvironment;
        private readonly WorkContext _workContext;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="loginService"></param>
        /// <param name="workContext"></param>
        /// <param name="hostingEnvironment"></param>

        public LoginController(LoginService loginService, WorkContext workContext, IWebHostEnvironment hostingEnvironment)
        {
            _loginService = loginService;
            _workContext = workContext;
            _hostingEnvironment = hostingEnvironment;
        }

        /// <summary>
        /// 用户登陆
        /// </summary>
        /// <param name="q"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        [Route("login/userlogin")]
        public ApiResponse<string> UserLogin([FromBody] LoginRequestDto q)
        {
            var result = _loginService.Login(q);
            return ApiResponse<string>.Succeeds(result);
        }

    }
}